// 公用js

/*窗口大小*/
var winWidth,winHeight;

/*触屏应用*/
var nowpageC=1; //当前页码数
var maxpage=3; //共计页码数
var prepageC=1;	//上一页页码数
var isAnimation=false; //是否正在动画
/*分享*/
function showShareBox(){		//打开分享窗口
	document.getElementById('sharebox').style.display="block";
	}
function closeSharebox(){		//关闭分享窗口
	document.getElementById('sharebox').style.display="none";
	}
/*浏览器监听*/
window.onload=function(){
	document.addEventListener("touchmove",function(event){
        event.preventDefault(); },false);
	$(document).swipeUp(function(){
            nextpage();
    })
	$(document).swipeDown(function(){
            prepage();
    })
	checkWinSize();
	$('.btn_zai').click(function(){
		aginDian();
	});
}
function nextpage(){		//下一页
	if(isAnimation==false){
		prepageC=nowpageC;
		if(nowpageC==maxpage){
			//nowpageC=1;
			return false;
			}
		else{
			nowpageC++;
			}
		gopage("up");
		}
	}
function prepage(){		//上一页
	if(isAnimation==false){
		prepageC=nowpageC;
		if(nowpageC==1){
			//nowpageC=maxpage;
			return false;
			}
		else{
			nowpageC--;
			}
		gopage("down");
		}
}
function aginDian(){		//再点一盏灯
	prepage();
	$('.click').parent().removeClass('page_opacity0To1');	
	$('.click').css('display','');
	$('.cheng').each(function() {
		$(this).removeClass('page_resizeBig');
	});
}
function gopage(state){		//翻页方法
	var nextpageCss=".page"+nowpageC;//当前页
	var prepageCss=".page"+prepageC;//上一页
	var Outcss,Incss;
	
	if(state=="up"){		//上翻
		Outcss="page-moveToTopbox";//100%位置-100%
		Incss="page-moveFromBottombox";//0%位置100%
		
		}
	else if(state=="down"){		//下翻
		Outcss="page-moveToBottombox";//100%位置是100%
		Incss="page-moveFromTopbox";//0%位置是-100%
		}
	isAnimation=true;
	$(nextpageCss).removeClass("hide");
	$(prepageCss).addClass(Outcss);
	$(nextpageCss).addClass(Incss);
	setTimeout(function(){	
		$(prepageCss).removeClass(Outcss);
		$(prepageCss).removeClass("page-current");
		$(prepageCss).addClass("hide");
		
		$(nextpageCss).addClass('page-current');
		$(nextpageCss).removeClass(Incss);
		isAnimation=false;
		},600);
}
$(".click").click(function(){
	$(this).hide();
	$(".btnu").addClass('page_opacity0To1');
//	$(".cheng").addClass('page_resizeBig');
	function ranum(){var a=Math.ceil(Math.random()*3)-1;return a}
	var r1=ranum();
	$(".cheng").eq(r1).addClass('page_resizeBig');
})

function checkWinSize(){		//检测窗口大小
	getWindowSize();
	document.getElementById('content').style.width=winWidth + "px";
	document.getElementById('content').style.height=winHeight + "px";
	document.getElementById('sharebox').style.width=winWidth+"px";
	document.getElementById('sharebox').style.height=winHeight+"px";
	}
//获取窗口大小
function getWindowSize(){
	//获取窗口宽度
	if (window.innerWidth){
		 winWidth = window.innerWidth;
		}
	else if ((document.body) && (document.body.clientWidth)){
		 winWidth = document.body.clientWidth;
		}
	//获取窗口高度
	if (window.innerHeight){
		 winHeight = window.innerHeight;
		}
	else if ((document.body) && (document.body.clientHeight)){
		 winHeight = document.body.clientHeight;
		}
	//通过深入Document内部对body进行检测，获取窗口大小
	if (document.documentElement  && document.documentElement.clientHeight &&document.documentElement.clientWidth){
	   winHeight = document.documentElement.clientHeight;
	   winWidth = document.documentElement.clientWidth;
		}
	}